package com.zhuzi.dto;

import cn.hutool.core.util.NumberUtil;
import com.zhuzi.common.utils.StringUtil;
import lombok.Data;
import lombok.experimental.Accessors;

import java.io.Serializable;
import java.math.BigDecimal;

/**
 * @author zhuzi
 * 2022/8/8 18:11
 */
@Data
@Accessors(chain = true)
public class KzzAndStockDTO implements Serializable {
    /**
     * 可转债代码
     */
    private String cbCode;
    /**
     * 正股代码
     */
    private String stockCode;
    /**
     * 可转债名称
     */
    private String cbName;
    private String stockName;

    private BigDecimal price;


    /**
     * 转债余额
     */
    private BigDecimal amount;

    /**
     * 转股溢价率
     */
    private BigDecimal premium;

    /**
     * 转股价值
     */
    private BigDecimal valuel;

    /**
     * 换手率
     */
    private BigDecimal rade;

    /**
     * 剩余本息
     */
    private BigDecimal cbPrice;

    /**
     * 剩余本息-税后
     */
    private BigDecimal cbPriceTax;

    /**
     * 剩余年限
     */
    private BigDecimal lessYear;

    /**
     * 市值
     */
    private BigDecimal marker;

    public KzzAndStockDTO setMarker(String marker) {
        this.marker = NumberUtil.toBigDecimal(marker);
        return this;
    }

    public KzzAndStockDTO setLessYear(String lessYear) {
        this.lessYear = NumberUtil.toBigDecimal(lessYear);
        return this;
    }

    public KzzAndStockDTO setCbPrice(String cbPrice) {
        try {
            this.cbPrice = new BigDecimal(StringUtil.replace(cbPrice, "%", "").trim());
        } catch (Exception e) {
            this.cbPrice = BigDecimal.ZERO;
        }
        return this;
    }

    public KzzAndStockDTO setCbPriceTax(String cbPriceTax) {
        try {
            this.cbPriceTax = new BigDecimal(StringUtil.replace(cbPriceTax, "%", "").trim());
        } catch (Exception e) {
            this.cbPriceTax = BigDecimal.ZERO;
        }
        return this;
    }

    public KzzAndStockDTO setPrice(String price) {
        try {
            this.price = new BigDecimal(price.trim());
        } catch (Exception e) {
            this.price = BigDecimal.ZERO;
        }
        return this;
    }

    public KzzAndStockDTO setAmount(String amount) {
        try {
            this.amount = new BigDecimal(amount.trim());
        } catch (Exception e) {
            this.amount = BigDecimal.ZERO;
        }
        return this;
    }

    public KzzAndStockDTO setValuel(String valuel) {
        try {
            this.valuel = new BigDecimal(valuel.trim());
        } catch (Exception e) {
            this.valuel = BigDecimal.ZERO;
        }
        return this;
    }

    /**
     * 换手率
     */
    public KzzAndStockDTO setRade(String rade) {
        try {
            this.rade = new BigDecimal(StringUtil.replace(rade, "%", "").trim());
        } catch (Exception e) {
            this.rade = BigDecimal.ZERO;
        }
        return this;
    }

    /**
     * 溢价率
     *
     * @param rade
     * @return
     */
    public KzzAndStockDTO setPremium(String rade) {
        try {
            this.premium = new BigDecimal(StringUtil.replace(rade, "%", "").trim());
        } catch (Exception e) {
            this.premium = BigDecimal.ZERO;
        }
        return this;
    }

    public static void main(String[] args) {
        System.out.println(NumberUtil.toBigDecimal(" 3.4年"));
        System.out.println(NumberUtil.toBigDecimal(" 3.4 "));
        System.out.println(NumberUtil.toBigDecimal(""));

    }
}
